// The Vue build version to load with the `import` command
// (runtime-only or standalone) has been set in webpack.base.conf with an alias.
import Vue from 'vue'
import App from './App'
import router from './router'

import axios from 'axios'
Vue.prototype.$axios = axios
Vue.prototype.$http = axios
// ElementUI
import ElementUI from 'element-ui';
import 'element-ui/lib/theme-chalk/index.css';
Vue.use(ElementUI)

// 引入 ECharts 模块
import echarts from 'echarts/lib/echarts'
// 引入折线图/柱状图等组件
import 'echarts/lib/chart/line'
import 'echarts/lib/chart/bar'
import 'echarts/lib/chart/radar'
import 'echarts/lib/chart/pie'
// 引入提示框和title组件，图例
import 'echarts/lib/component/tooltip'
import 'echarts/lib/component/title'
import 'echarts/lib/component/legend'
import 'echarts/lib/component/legendScroll' //图例滚动
Vue.prototype.$echarts = echarts

Vue.config.productionTip = false

// vue项目中使用RSA加密
import JSEncrypt from 'jsencrypt';
Vue.prototype.$getRsaCode = async function (str) { // 注册方法
  return new Promise((resolve, reject) => {
    this.$axios.create({
        headers: {
          "Content-Type": "multipart/form-data"
        }
      })
      .get('/xd/sys/getkey')
      .then(res => {
        let pubKey = res.data; // ES6 模板字符串 引用 rsa 公钥
        let encryptStr = new JSEncrypt();
        encryptStr.setPublicKey(pubKey); // 设置 加密公钥
        let data = encryptStr.encrypt(str.toString()); // 进行加密
        // console.log(data)
        resolve(data)
      })
      .catch(err => {
        this.$message.error('网络异常,请稍后重试')
      })
  })
}
new Vue({
  router,
  render: h => h(App)
}).$mount("#app")